package com.zy.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @auther zzyy
 * @create 2025-01-03 13:50
 */
@Aspect
@Component
@Slf4j
public class DemoAspect
{
    @Pointcut("(@target(org.springframework.web.bind.annotation.RestController)) " +
            "&& within(com.zy..*) && execution(public * *(..))")

    public void pointcut() {}

    @Around(value = "pointcut()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable
    {
        Object  res =null;
        try{
            log.info("前置通知");
            res = proceedingJoinPoint.proceed();
            log.info("返回通知");
//        }
//        catch (Throwable e) {
//        log.info("异常通知");
    } finally {
        //后置通知
        log.info("后置通知");
    }


        return res;
    }
}
